#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QPicture>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建Qpicture对象
    QPicture picture;
    //创建绘画者
    QPainter painter;

    //开始往picture绘画
    painter.begin(&picture);
    painter.setPen(QPen(Qt::red));
    painter.drawEllipse(100,100,50,50);
    //结束绘画
    painter.end();
    //保存图片
    picture.save("D:\\Codes\\qt\\QPicture\\picture.pic");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    //在widget控件创建的时候会触发这个事件
    //我们把picture保存的绘画重新执行一边
    QPainter painter(this);

    QPicture pict;
    pict.load("D:\\Codes\\qt\\QPicture\\picture.pic");

    //绘制图片
    painter.drawPicture(0,0,pict);
}

